package test;

import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

import com.survey.R;
import com.survey.activity.ChoiceActivity;

public class MultiChoiceTick extends ChoiceActivity {
	
	private ListView	lvCheckBox;
	private Button		btnCheckAll, btnClearALl;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.multichoicetick);
		initLayout();
	}
	
	public void initLayout() {
		
		btnCheckAll = (Button) findViewById(R.id.btnCheckAll);
		btnClearALl = (Button) findViewById(R.id.btnClearAll);
		lvCheckBox = (ListView) findViewById(R.id.lvCheckBox);
		
		lvCheckBox.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
		lvCheckBox.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice,
				getQuestionList()));
		
		btnCheckAll.setOnClickListener(this);
		btnClearALl.setOnClickListener(this);
	}
	
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.btnCheckAll:
				for (int i = 0; i < lvCheckBox.getAdapter().getCount(); i++) {
					lvCheckBox.setItemChecked(i, true);
				}
				break;
			
			case R.id.btnClearAll:
				for (int i = 0; i < lvCheckBox.getAdapter().getCount(); i++) {
					lvCheckBox.setItemChecked(i, false);
				}
				break;
			default:
				break;
		}
	}
}